package com.itheima.text01;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

public class Demo03 {
    //随机点名器03，第三次必须是张三
    public static void main(String[] args) throws IOException {
        //先读取学生信息到集合中
        BufferedReader br = new BufferedReader(new FileReader("11.txt"));
        ArrayList<String> list=new ArrayList<>();

        String line;
        while((line=br.readLine())!=null)
        {
            list.add(line);
        }
        br.close();

        //读取当前程序已经运行的次数
        BufferedReader br2= new BufferedReader(new FileReader("count.txt"));

        String s = br2.readLine();
        int count = Integer.parseInt(s);//程序已经执行的次数
        count++;
        if(count==3)
        {
            System.out.println("张三");
        }else //还是要随机输出他人的姓名
        {
            Collections.shuffle(list);
            String str = list.get(0);
            String name = str.split("-")[0];
            System.out.println(name);
        }


        //重新将次数存入文件中
        BufferedWriter bw = new BufferedWriter(new FileWriter("count.txt"));
        bw.write(count+"");
        bw.close();

    }
}
